package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;;
import com.example.demo.pojo.entity.QuestionLabel;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface QuestionLabelMapper extends BaseMapper<QuestionLabel> {
    @Select("select count(*) from test.question_label")
    int test();

    /*
    * 查找
    * */
    //查询某个知识点所有题型--根据rootId
    @Select("select * from test.question_label where node_id like CONCAT( #{rootId}, '-','%')")
    List<QuestionLabel>initQuestionLabel(int rootId);
    //根据名字模糊查找
    @Select("select * from test.question_label where name like CONCAT('%', #{name}, '%')")
    List<QuestionLabel>searchQuestionLabel(String name);
    //查找节点下的所有子节点
    @Select("select * from test.question_label where node_id like CONCAT(#{nodeId}, '%') and level=#{level}")
    List<QuestionLabel> searchChildrenNode(@Param("nodeId") String nodeId, @Param("level") Integer level);
    //查找根节点
    @Select("select * from test.question_label where parent_id=0")
    QuestionLabel searchRootNode();
    //根据名字完全匹配查找节点
    @Select("SELECT * FROM test.question_label WHERE name = #{name}")
    List<QuestionLabel> searchByName(String name);
    //根据id查找题型
    @Select("select * from test.question_label WHERE id=#{id}")
    QuestionLabel searchById(Integer id);
    //根据当前节点，查找所有父类节点

    //根据当前节点,查找其下一层节点
    @Select("select * from test.question_label where node_id like CONCAT(#{nodeId}, '%') and level=#{level}")
    List<QuestionLabel>searchChildrenByNodeId(String nodeId,Integer level);
    /*
    * 操作
    * */
    //添加一个新题目类型
    @Insert("INSERT INTO test.question_label(name) VALUES(#{name})")
    @SelectKey(keyColumn="id", resultType=Integer.class, before=false, statement="SELECT LAST_INSERT_ID()",  keyProperty = "id")
    Long insertAndReturnKey(QuestionLabel questionLabel);
    //更新题目类型信息
    void updateQuestionLabel(QuestionLabel questionLabel);
}
